<?php 
	if(session_id()=="")	
			session_start();?>
<?php 
	
class Application_Model_service_TaiKhoanService implements Application_Model_serviceInf_TaiKhoanServiceInf {
	protected static $_instance=null;
	
	protected function __construct(){
		
	}
	public static function getInstance(){
		if(self::$_instance==null) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	/**
	 * @param unknown_type $username
	 * @param unknown_type $password
	 * @param unknown_type $hoVaTen
	 * @param unknown_type $gioiTinh
	 * @param unknown_type $cmnd
	 * @param unknown_type $diaChi
	 * @param unknown_type $soDienThoai
	 * @param unknown_type $email
	 * @param unknown_type $nhanThongTinQuaEmail
	 */
	public function taoTaiKhoan($username, $password, $hoVaTen, $gioiTinh, $cmnd, $diaChi, $soDienThoai, $email, $nhanThongTinQuaEmail) {
			$nhanthongtintumail=(int)$nhanThongTinQuaEmail;
			//set account
		$taikhoan=new Application_Model_bean_TaiKhoan();
		$taikhoan->setUsername($username);
		$taikhoan->setPassword($password);
		$taikhoan->setHoVaTen($hoVaTen);
		$taikhoan->setDiaChi($diaChi);
		$taikhoan->setCmnd($cmnd);
		$taikhoan->setGioiTinh($gioiTinh);
		$taikhoan->setEmail($email);
		$taikhoan->setNhanThongTinQuaEmail($nhanthongtintumail);
		$taikhoan->setSoDienThoai($soDienThoai);
		//set mac dinh chua kich hoat va khong bi xoa
		
		$taikhoan->setBiXoaHayChua(0);//chua bi xoa
		$taikhoan->setTrangThai(0);//chua kich hoat
		//Quyen han mac dinh la khach,user
		
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$result=$accountdao->insertTaiKhoa($taikhoan);
		return $result;
	}

	/**
	 * 
	 */
	public function suathongtinTaiKhoan($arrayinformation) {
		$id=$arrayinformation["maTaiKhoan"];
		$password=$arrayinformation["password"];	
		$hoten=$arrayinformation["hoten"];
		$email=$arrayinformation["email"];
		$cmnd=$arrayinformation["cmnd"];
		$diachi=$arrayinformation["diachi"];
		$sodienthoai=$arrayinformation["sodienthoai"];
		
		$taikhoan=new Application_Model_bean_TaiKhoan();
		$taikhoan->setMaTaiKhoan($id);
		$taikhoan->setPassword($password);
		$taikhoan->setHoVaTen($hoten);
		$taikhoan->setDiaChi($diachi);
		$taikhoan->setEmail($email);
		$taikhoan->setSoDienThoai($sodienthoai);
		$taikhoan->setCmnd($cmnd);
		
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$result=$accountdao->editTaiKhoan($taikhoan);
		return $result;
	}

	/**
	 * @param unknown_type $id
	 */
	public function xoaTaiKhoan($id) {
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$result=$accountdao->removeTaiKhoan($id);
		
		
		return  $result;	
		
		
	}

	/**
	 * @param unknown_type $id
	 */
	public function timkiemTaiKhoan($id) {
			$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
			$taikhoan=$accountdao-> searchTaiKhoan($id) ;
				
			return $taikhoan;
	}

	/**
	 * @param unknown_type $id
	 */
	public function kichhoaTtaiKhoan($id) {
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$result=$accountdao->activeTaiKhoan($id);
	}
/**
	 * @param unknown_type $username
	 * @param unknown_type $password
	 */
	public function login($username, $password) {
			$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
			$result=$accountdao->login($username,$password);
			return $result;
	
	}

/**
	 * @param unknown_type $maquyen
	 */
	public function checkQuyen($maquyen) {
		$result=false;
		$id=$_SESSION['id'];
		if($id!=null){ 
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$result=$accountdao->checkQuyen($id,$maquyen);
		}
		return $result;
	}
/**
	 * @param unknown_type $id
	 * @param unknown_type $array
	 */
	public function ganQuyen($id, $array) {
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$result=$accountdao->ganQuyen($id,$array);
		return $result;
	}

/**
	 * @param unknown_type $id
	 */
	public function LietKeQuyen($id) {
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		return $accountdao->getQuyen($id);
	}

/**
	 * @param unknown_type $kichhoatchua
	 */
	public function lietketatcaTaikhoan($active) {
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
//		echo $active;
		return $accountdao->getAllTaiKhoan($active);
//		return null;
	}
/**
	 * @param unknown_type $username
	 */
	public function timkiemtheousername($username) 
	{
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
			return $accountdao->searchbyusername($username);
	}

/**
	 * @param unknown_type $ten
	 */
	public function timkiemtheoten($ten) 
	{
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		return $accountdao->searchbyten($ten) ;
	
	}

/**
	 * @param unknown_type $array
	 */
	public function timkiemnangcao($array) 
	{
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		return $accountdao->searchhightlevel($array);	
		
	}
	public function isLogin(){
		$account=NULL;
		$id=$_SESSION['id'];
		if($id=='') return $account;
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$account=$accountdao->searchTaiKhoan($id);
		return $account;
		
	}
	public function taoTaiKhoanAdmin ($username, $password, $hoVaTen, $gioiTinh, $cmnd, $diaChi, $soDienThoai, $email, $nhanThongTinQuaEmail) {
			$nhanthongtintumail=(int)$nhanThongTinQuaEmail;
			//set account
		$taikhoan=new Application_Model_bean_TaiKhoan();
		$taikhoan->setUsername($username);
		$taikhoan->setPassword($password);
		$taikhoan->setHoVaTen($hoVaTen);
		$taikhoan->setDiaChi($diaChi);
		$taikhoan->setCmnd($cmnd);
		$taikhoan->setGioiTinh($gioiTinh);
		$taikhoan->setEmail($email);
		$taikhoan->setNhanThongTinQuaEmail($nhanthongtintumail);
		$taikhoan->setSoDienThoai($soDienThoai);
		//set mac dinh chua kich hoat va khong bi xoa
		
		$taikhoan->setBiXoaHayChua(0);//chua bi xoa
		$taikhoan->setTrangThai(0);//chua kich hoat
		//Quyen han mac dinh la khach,user
		
		$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
		$result=$accountdao->insertTaiKhoanAdmin($taikhoan);
		return $result;
	}
		public function isAdmin(){
			$id=$_SESSION['id'];
			if($id=='') return false;
			$accountdao=Application_Model_dataDAO_TaiKhoanDAO::getInstance();
			$result=$accountdao->checkAdmin($id);
			return $result;
			
			
		}	
}

?>